Live modification of the pitch and time-scale of sounds

Aupyom was mainly designed so it is really easily to modify the pitch ant time-scale of sounds. It has been created in the Poppy-project context where robots are used as educational tools. Interactivity was thus a key feature.

In this notebook, you will see:

  • how to change the pitch, and time-scale of sounds
  • see how interactive widgets can be used to lively modify those features

Load sounds into the sampler

First, we load sounds into the sampler (please see this notebook for details).


In [ ]:
from aupyom import Sampler, Sound
from aupyom.util import example_audio_file

sampler = Sampler()

audio_file = example_audio_file()
s1 = Sound.from_file(audio_file)

Start playing sound:


In [ ]:
sampler.play(s1)

Shift the pitch of sounds

You can directly change the pitch of any sound directly via a property:


In [ ]:
s1.pitch_shift = 3

Note that you can modify the pitch while the sounds is played.

You can also decrease the pitch:


In [ ]:
s1.pitch_shift = -2

You can "reset" the pitch to its base value:


In [ ]:
s1.pitch_shift = 0

Modify the time-scale: without pitch modification

You can also speed-up or slow down sound using the stretch_factor property.

For instance, if you want to double the speed by 2x:


In [ ]:
s1.stretch_factor = 2.0

You can also slow it down:


In [ ]:
s1.stretch_factor = 0.5

And to reset to its initial play speed:


In [ ]:
s1.stretch_factor = 1.0

Using widgets to lively modify sounds

You can use the notebook widgets to create an interface and easily modify sounds:


In [ ]:
def modify_sound(pitch, stretch):
    s1.pitch_shift = pitch
    s1.stretch_factor = stretch

In [ ]:
from ipywidgets import interact, FloatSlider

sampler.play(s1)

interact(modify_sound,
         pitch=FloatSlider(min=-10, max=10, value=0, step=0.5),
         stretch=FloatSlider(min=0.1, max=10, value=1.0, step=0.1));

In [ ]: